<!DOCTYPE html>
<html>

	<head>
		<meta charset="UTF-8">
		<link rel="stylesheet" type="text/css" href="../../../Themes/default/easyui.css">
		<link rel="stylesheet" type="text/css" href="../../../Themes/icon.css">
		<link rel="stylesheet" type="text/css" href="../../../CSS/demo.css">
		<link rel="stylesheet" type="text/css" href="../../../CSS/common.css">
	</head>

	<body style="padding:0px;background-color: white">
		<div id="toolbar" class="receipts_toolbar_style"></div>
		<form id="ff" action="#" method="post">
			<table cellpadding="5" class="displaytable" style="text-align: left;width: 80%;margin: 0 auto;">
				<tr>
					<td width="20%">
						<h id="star">* </h>采购员</td>
					<td width="30%">
						<input class="easyui-combobox" style="width: 100%" type="text" id="input_PURCHASE_MAN" name="PURCHASE_MAN" data-options="disabled:true" />
					</td>
					<td width="20%">
						<h id="star">* </h>用户组</td>
					<td width="30%">
						<input class="easyui-textbox" style="width: 100%;" type="text" name="CUSTOMER_TYPE" id="input_CUSTOMER_TYPE" data-options="disabled:true"></input>
					</td>

				</tr>
				<tr>
					<td>
						<h id="star">* </h>采购时间</td>
					<td>
						<input class="easyui-datebox" style="width: 100%;" type="text" name="PURCHASE_DATE" id="input_PURCHASE_DATE" data-options="disabled:true"></input>
					</td>
					<td>
						<h id="star">* </h>采购单号</td>
					<td>
						<input class="easyui-textbox" style="width: 100%;" type="text" name="ORDER_NO" id="input_ORDER_NO" data-options="disabled:true"></input>
					</td>
				</tr>
				<tr>
					<td>
						<h id="star">* </h>仓库</td>
					<td>
						<input class="easyui-textbox" style="width: 100%;" type="text" name="STOREHOUSE_NAME" id="input_STOREHOUSE_NAME" data-options="disabled:true"></input>
					</td>

				</tr>
				<tr id="nodisplay" style="display: none">
					<td>
						<h id="star">* </h>仓库ID</td>
					<td>
						<input class="easyui-textbox" style="width:100%;" type="text" name="STOREHOUSE_ID" id="input_STOREHOUSE_ID" data-options="prompt:'由系统自动生成，不需填写',disabled:true," />
					</td>

				</tr>
			</table>
			<table id="tt" class="table_style" style="width: 100%;">
			</table>
		</form>

		</div>
		<div style="margin-left: 20%;" id="new_footer">

		</div>
		<div id="dlg" class="hiddenDialog">
			<iframe id="ifrmEdit" style="width: 100%;height: 100%;" frameborder="0" scrolling="no"></iframe>
		</div>

	</body>
	<script type="text/javascript" src="../../../JS/jquery.min.js"></script>
	<script type="text/javascript" src="../../../JS/jquery.easyui.min.js"></script>
	<script type="text/javascript" src="../../../JS/common.js"></script>
	<script type="text/javascript" src="../../../JS/finance.js"></script>
	<script type="text/javascript" src="../../../JS/detailView.js"></script>
	<script type="text/javascript" src="../../../JS/SHA-1.js"></script>
	<script type="text/javascript">
		var currid = AddFlag; //当前页面的ID
		var warehoseinID;
		var currWarehouseinID = ""; //入库单的ID
		var purchaseOrderID = getID(); //获取上个页面传回的ID
		var gRowLength = 0;
		var _detailToolbarData;
		GetDetailTable();
		var updateData;
		$(document).ready(function() {
			if(purchaseOrderID != AddFlag && purchaseOrderID != undefined) {
				currid = purchaseOrderID;
				loadRemote();
			}
			if(purchaseOrderID == undefined) { //如果没有数据
				$.messager.alert("警告", "未能获取采购单信息");
			}
		});

		addFooter($("#new_footer"));
		//增加单据的toolbar

		var toolbardata = [{
				"icon": "icon-add",
				"func": "newProviderData()",
				"functionname": "新建入库单"
			}, {
				"icon": "icon-edit",
				"func": "editProviderData()",
				"functionname": "修改入库单"
			},
			{
				"icon": "icon-left",
				"func": "expand()",
				"functionname": "全部展开"
			},
			{
				"icon": "icon-right",
				"func": "collapse()",
				"functionname": "全部关闭"
			}
		];

		///tooldata为新增的toolbar数据
		content = AddReceiptsToolBar(0, toolbardata);
		$("#toolbar").append(content); /*在ID=toolbar的标记后面添加content中的内容*/
		function editProviderData() {
			if(warehoseinID == undefined) {
				$.messager.alert("警告", "请选中你需要修改的数据");
			} else {
				var pLocation = "";
				pLocation = "UI/LOGISTICS/WareHouseScheduleProvider/WareHouseScheduleProviderAdd.html?PurchaseOrderid=" + purchaseOrderID + "&WarehouseID=" + warehoseinID; /*将BoothManagementAdd.html的相对路径与被选中行的ID赋值给pLocation*/
				AddTabIn("修改入库单", parent.$("#tabs"), pLocation);
			}
		}

		function collapse() {
			for(var i = 0; i < gRowLength; i++) {
				$("#tt").datagrid("collapseRow", i);
			}

		}

		function expand() {
			for(var i = 0; i < gRowLength; i++) {
				$("#tt").datagrid("expandRow", i);
			}
		}

		function newProviderData() {
			//			if(updateData.STATE=="入库完成")
			//			{
			//				$.messager.alert("警告","已经入库完成,不能追加入库");
			//				return;
			//			}
			var pLocation = "";
			pLocation = "UI/LOGISTICS/WareHouseScheduleProvider/WareHouseScheduleProviderAdd.html?PurchaseOrderid=" + purchaseOrderID + "&WarehouseID=" + AddFlag; /*将BoothManagementAdd.html的相对路径与被选中行的ID赋值给pLocation*/
			AddTabIn("新建入库单", parent.$("#tabs"), pLocation);

		}

		function getRemoteData(_url) //统一获取远程的数据
		{
			$.ajax({ //调用ajax方法，从服务器获取到该订单的所有数据
				type: "get",
				url: _url,
				dataType: "json", //服务器返回的数据类型
				success: function(result) {
					if(result != null) {
						updateData = deepCopy(result);
						getFormData(result);
						gRowLength = result.rows.length;
						currid = result.ID;
						var _data = result.rows; //将获取到的数据中字头为rows的数据赋值给_data
						$('#tt').datagrid('loadData', _data); //调用easyui的loadData方法，将数据写入id为tt的datagrid中
					}

				}, //请求成功后，接受服务器传来的Json字符串，并做相应的处理
				error: function(xhr, status, error) {
					$.messager.alert("错误", "请求失败!");
				}
			});
		}
		//////////
		function loadRemote() { //载入服务器上的数据，用于修改以及查看更多的时候调用，根据id是否等于-1来判断
			var _url = RemoteLinkAddress + '/logistics/purchaseorder/findbyid.do?ID=' + currid;
			getRemoteData(_url);
		}

		function GetDetailTable() { //构造datagrid中的数据
			$('#tt').datagrid({
				height: 310,
				view: detailview,
				singleSelect: 'true', //是否单选：是
				rownumbers: 'true',
				columns: [
					[{
						field: 'ID',
						title: '明细ID',
						width: '10%',
						align: 'center',

					}, {
						field: 'INTERNALTRADE_ID',
						title: '内部商品ID',
						width: '10%',
						align: 'center',

					}, {
						field: 'INTERNAL_NAME',
						title: '*内部商品名',
						width: '25%',
						align: 'center',

					}, {
						field: 'INTERNAL_TYPE',
						title: '*内部商品类型',
						width: '10%',
						align: 'center',

					}, {
						field: 'UNIT_NAME',
						title: '*单位',
						width: '5%',
						align: 'center',

					}, {
						field: 'AMOUNT',
						title: '*应采购数量',
						width: '8%',
						align: 'center',

					}, {
						field: 'STOCKS',
						title: '*库存量',
						width: '8%',
						align: 'center',

					}, {
						field: 'EVALUATE_AMOUNT',
						title: '*预估采购数量',
						width: '8%',
						align: 'center',

					}, {
						field: 'REAL_AMOUNT',
						title: '*已采购数量',
						width: '8%',
						align: 'center',

					}, ]
				],
				detailFormatter: function(index, row) {
					return '<div style="padding:2px"><table class="ddv"></table></div>';
				},
				onExpandRow: function(index, row) {
					var _url = RemoteLinkAddress + "/logistics/purchaseorder/listInByDetailId.do?ID=" + row.ID;
					var ddv = $(this).datagrid('getRowDetail', index).find('table.ddv');
					ddv.datagrid({
						url: _url,
						fitColumns: true,
						singleSelect: true,
						rownumbers: true,
						loadMsg: '',
						height: 'auto',
						columns: [
							[{
								field: 'ck',
								checkbox: 'true',
							}, {
								field: 'ORDER_ID',
								title: '入库单ID',
								width: '10%'
							}, {
								field: 'ORDER_NO',
								title: '入库单编号',
								width: '10%'
							}, {
								field: 'PROVIDER_NAME',
								title: '供应商名称',
								width: '20%',
								align: 'center'
							}, {
								field: 'INTERNAL_NAME',
								title: '内部商品名称',
								width: '10%',
								align: 'center'
							}, {
								field: 'UNIT_NAME',
								title: '单位',
								width: '5%',
								align: 'center'
							}, {
								field: 'QUALITY',
								title: '产品质量',
								width: '5%',
								align: 'center'
							}, {
								field: 'PROVIDER_AMOUNT',
								title: '入库数量',
								width: '8%',
								align: 'center'
							}, {
								field: 'ISVERIFY',
								title: '审核状态',
								width: '8%',
								align: 'center',
								formatter: function(value, row, index) {
									return verifyStatus(value, false);
								}
							}, ]
						],
						onResize: function() {
							$('#tt').datagrid('fixDetailRowHeight', index);
						},
						onLoadSuccess: function() {
							setTimeout(function() {
								$('#tt').datagrid('fixDetailRowHeight', index);
							}, 0);
						},
						onCheck: function(index, row) {
							warehoseinID = row.ORDER_ID;
						},
						onDblClickRow: function(index, row) {
							var pLocation = "";
							pLocation = "UI/LOGISTICS/WareHouseScheduleProvider/WareHouseScheduleProviderAdd.html?PurchaseOrderid=" + purchaseOrderID + "&WarehouseID=" + row.ORDER_ID; /*将BoothManagementAdd.html的相对路径与被选中行的ID赋值给pLocation*/
							AddTabIn("修改入库单", parent.$("#tabs"), pLocation);
						}
					});
					$('#tt').datagrid('fixDetailRowHeight', index);
				}

			});
		}
	</script>

</html>